<template>
    <div class="app-container">
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
            <el-form-item label="用户名称" prop="nickName">
                <el-input v-model="queryParams.nickName" placeholder="请输入名称" clearable maxlength="10" show-word-limit
                    @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="联系方式" prop="phoneNumber">
                <el-input v-model="queryParams.phoneNumber" placeholder="请输入联系方式" clearable maxlength="11"
                    show-word-limit @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="测评时间" prop="nickName">
                <el-date-picker v-model="dates" type="daterange" range-separator="至" start-placeholder="开始日期"
                    @change="changeDate" format="yyyy-MM-dd" value-format="yyyy-MM-dd" end-placeholder="结束日期">
                </el-date-picker>
            </el-form-item>
            <el-form-item label="测评" prop="appraisalId">
                <el-select v-model="queryParams.appraisalId">
                    <el-option v-for="item in appraisalListData" :key="item.id" :value="item.id"
                        :label="item.appraisalName">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="测评状态" prop="appraisalStatus">
                <el-select v-model="queryParams.appraisalStatus">
                    <el-option v-for="item in appraisalStatusList" :key="item.id" :value="item.id" :label="item.name">
                    </el-option>
                </el-select>
            </el-form-item>

            <el-form-item>
                <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>

        <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
                <el-button type="warning" icon="el-icon-download" size="mini" @click="handleExport"
                    v-hasPermi="['business:PersonevaluationReport:export']">导出</el-button>
            </el-col>
            <el-col :span="1.5">
                <el-button type="danger"  icon="el-icon-delete" size="mini" :disabled="multiple"
                    @click="handleDelete" v-hasPermi="['business:PersonevaluationReport:remove']">删除</el-button>
            </el-col>
            <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>
        <el-table v-loading="loading" :data="configurationList" @selection-change="handleSelectionChange">
            <el-table-column type="selection" width="55" align="center" />
            <el-table-column label="序号" align="center" width="55" type="index" />
            <el-table-column label="测评名称" align="center" prop="appraisalName" min-width="200"
                :show-overflow-tooltip="true" />
            <el-table-column label="用户名称" align="center" prop="nickName" min-width="100"
                :show-overflow-tooltip="true" />
            <el-table-column label="性别" align="center" prop="userSex" min-width="100" :show-overflow-tooltip="true">
                <template v-slot="scope">
                    <div v-if="scope.row.userSex == 0">男</div>
                    <div v-if="scope.row.userSex == 1">女</div>
                </template>
            </el-table-column>
            <el-table-column label="联系方式" align="center" prop="phoneNumber" min-width="150"
                :show-overflow-tooltip="true" />

            <el-table-column label="支付金额" align="center" prop="amount" min-width="100" :show-overflow-tooltip="true" />

            <el-table-column label="得分" align="center" prop="appraisalScore" min-width="100"
                :show-overflow-tooltip="true" />
            <el-table-column label="预警状态" align="center" prop="appraisalAbnormalStatus" min-width="100"
                :show-overflow-tooltip="true">
                <template v-slot="scope">
                    <el-tag :type="dictValueToTagType(scope.row.appraisalAbnormalStatus)">
                        {{ getDictLabel('abnormalstatus', scope.row.appraisalAbnormalStatus)
                        }}
                    </el-tag>
                </template>
            </el-table-column>
            <el-table-column label="评测状态" align="center" prop="appraisalStatus" min-width="100"
                :show-overflow-tooltip="true">
                <template v-slot="scope">
                    <div v-if="scope.row.appraisalStatus == 0">进行中</div>
                    <div v-if="scope.row.appraisalStatus == 1">已完成</div>
                </template>
            </el-table-column>
            <!-- <el-table-column label="咨询方式" align="center" prop="consultationMethod" min-width="200"
                :show-overflow-tooltip="true">
                <template v-slot="scope">
                    <div v-if="scope.row.consultationMethod == 1">电话咨询</div>
                    <div v-if="scope.row.consultationMethod == 2">线上语音</div>
                    <div v-if="scope.row.consultationMethod == 3">线上视频</div>
                    <div v-if="scope.row.consultationMethod == 4">当面咨询</div>
                </template>
            </el-table-column> -->
            <el-table-column label="开始时间" align="center" prop="appraisalBeginDate" min-width="160"
                :show-overflow-tooltip="true" />
            <el-table-column label="结束时间" align="center" prop="appraisalFinishDate" min-width="160"
                :show-overflow-tooltip="true" />

            <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right" width="80">
                <template slot-scope="scope">

                    <el-button size="mini" type="text" @click="handleViews(scope.row)"
                        v-hasPermi="['report:PersonevaluationReport:list']">查看报告</el-button>
                </template>
            </el-table-column>
        </el-table>

        <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum"
            :limit.sync="queryParams.pageSize" @pagination="getList" />


        <el-dialog title="评测结果分析" :visible.sync="openResult" width="700px" append-to-body>
            <div style="display: flex;justify-content: flex-end;margin: 10px 0;">
                <el-button type="warning" icon="el-icon-download" size="mini" @click="generateReport">导出</el-button>
            </div>

            <vue-html2pdf ref="html2Pdf" :manual-pagination="false" pdf-content-width="100%" :show-layout="false"
                :enable-download="true" :preview-modal="false" :paginate-elements-by-height="3000" :html-to-pdf-options="{
                    margin: 0,
                    filename: '报告.pdf',
                    image: { type: 'jpeg', quality: 0.98 },
                    html2canvas: { scale: 2, useCORS: true },
                    jsPDF: { unit: 'mm', format: 'a4', orientation: 'portrait' }
                }">
                <section slot="pdf-content">
                    <div class="exportPdfData">
                        <scl90-vue ref="scl90Ref" :appraisalId="appraisalId" :detailId="detailId"
                            v-if="appraisalId == 8"></scl90-vue>
                        <anxiety-self-assessment ref="anxietyRef" :appraisalId="appraisalId" :detailId="detailId"
                            v-if="appraisalId == 7"></anxiety-self-assessment>
                        <burnout ref="burnoutRef" :appraisalId="appraisalId" :detailId="detailId"
                            v-if="appraisalId == 1">
                        </burnout>
                        <careerInterest ref="careerRef" :appraisalId="appraisalId" :detailId="detailId"
                            v-if="appraisalId == 5">
                        </careerInterest>
                        <childRelationshipAssessment ref="AssessmentRef" :appraisalId="appraisalId" :detailId="detailId"
                            v-if="appraisalId == 10">
                        </childRelationshipAssessment>
                        <childRelationshipDiagnosis ref="DiagnosisRef" :appraisalId="appraisalId" :detailId="detailId"
                            v-if="appraisalId == 4">
                        </childRelationshipDiagnosis>
                        <depressionSelfAssessment ref="depressionRef" :appraisalId="appraisalId" :detailId="detailId"
                            v-if="appraisalId == 2">
                        </depressionSelfAssessment>
                        <maritalQuality ref="maritalRef" :appraisalId="appraisalId" :detailId="detailId"
                            v-if="appraisalId == 9">
                        </maritalQuality>
                        <perceivedStress ref="stressRef" :appraisalId="appraisalId" :detailId="detailId"
                            v-if="appraisalId == 6">
                        </perceivedStress>
                        <socialSupportRatingScale ref="socialSupportRef" :appraisalId="appraisalId" :detailId="detailId"
                            v-if="appraisalId == 3"></socialSupportRatingScale>
                    </div>

                </section>
            </vue-html2pdf>
            <scl90-vue ref="scl90Ref" :appraisalId="appraisalId" :detailId="detailId"
                v-if="appraisalId == 8"></scl90-vue>
            <anxiety-self-assessment ref="anxietyRef" :appraisalId="appraisalId" :detailId="detailId"
                v-if="appraisalId == 7"></anxiety-self-assessment>
            <burnout ref="burnoutRef" :appraisalId="appraisalId" :detailId="detailId" v-if="appraisalId == 1"></burnout>
            <careerInterest ref="careerRef" :appraisalId="appraisalId" :detailId="detailId" v-if="appraisalId == 5">
            </careerInterest>
            <childRelationshipAssessment ref="AssessmentRef" :appraisalId="appraisalId" :detailId="detailId"
                v-if="appraisalId == 10">
            </childRelationshipAssessment>
            <childRelationshipDiagnosis ref="DiagnosisRef" :appraisalId="appraisalId" :detailId="detailId"
                v-if="appraisalId == 4">
            </childRelationshipDiagnosis>
            <depressionSelfAssessment ref="depressionRef" :appraisalId="appraisalId" :detailId="detailId"
                v-if="appraisalId == 2">
            </depressionSelfAssessment>
            <maritalQuality ref="maritalRef" :appraisalId="appraisalId" :detailId="detailId" v-if="appraisalId == 9">
            </maritalQuality>
            <perceivedStress ref="stressRef" :appraisalId="appraisalId" :detailId="detailId" v-if="appraisalId == 6">
            </perceivedStress>
            <socialSupportRatingScale ref="socialSupportRef" :appraisalId="appraisalId" :detailId="detailId"
                v-if="appraisalId == 3"></socialSupportRatingScale>
        </el-dialog>
    </div>
</template>

<script>
import VueHtml2pdf from 'vue-html2pdf'
import scl90Vue from '../cnps/scl90.vue'; //8
import anxietySelfAssessment from '../cnps/anxietySelfAssessment.vue'; //焦虑自我评估7
import burnout from '../cnps/burnout.vue'; //职业倦怠1
import careerInterest from '../cnps/careerInterest.vue'; //霍兰德职业兴趣5
import childRelationshipAssessment from '../cnps/childRelationshipAssessment.vue'; //亲子关系诊断10
import childRelationshipDiagnosis from '../cnps/childRelationshipDiagnosis.vue'; //亲子关系评估4
import depressionSelfAssessment from '../cnps/depressionSelfAssessment.vue'; //抑郁自我评估2
import maritalQuality from '../cnps/maritalQuality.vue'; //婚姻9
import perceivedStress from '../cnps/perceivedStress.vue'; //知觉压力6
import socialSupportRatingScale from '../cnps/socialSupportRatingScale.vue'; //社会支持评分量表3
import { userAppraisalList1 ,delappraisal} from '@/api/member'
import { appraisalList } from "@/api/evaluation/appraisalTopic";
export default {
    name: "ConfigurationMemberReport",
    dicts: ['abnormalstatus', 'sys_user_sex'],
    components: {
        VueHtml2pdf,
        scl90Vue,
        anxietySelfAssessment,
        burnout,
        careerInterest,
        childRelationshipAssessment,
        childRelationshipDiagnosis,
        depressionSelfAssessment,
        maritalQuality,
        perceivedStress,
        socialSupportRatingScale
    },
    data() {
        return {
            appraisalStatusList: [
                {
                    id: '0',
                    name: '进行中'
                },
                {
                    id: '1',
                    name: '已完成'
                }
            ],
            appraisalId: '',
            detailId: '',
            openResult: false,
            appraisalListData: [],
            dates: [],
            // 遮罩层
            loading: true,
            // 选中数组
            ids: [],
            // 非单个禁用
            single: true,
            // 非多个禁用
            multiple: true,
            // 显示搜索条件
            showSearch: true,
            // 总条数
            total: 0,
            // 配置维护表格数据
            configurationList: [],
            // 弹出层标题
            title: "",
            // 是否显示弹出层
            open: false,
            // 查询参数
            queryParams: {
                phoneNumber: undefined,
                nickName: undefined,
                pageNum: 1,
                pageSize: 10,
                userType: 1,
                appraisalStatus: undefined,
                params: {
                    endTime: undefined,
                    beginTime: undefined,
                }
            }
        };
    },
    created() {
        this.getList();
        appraisalList().then(res => {
            this.appraisalListData = res.rows
        })
    },
    methods: {
        /** 删除按钮操作 */
        handleDelete() {
            const ids = this.ids
            this.$modal.confirm('是否确认删除报告数据项？').then(function () {
                return delappraisal(ids)
            }).then(() => {
                this.getList()
                this.$modal.msgSuccess("删除成功")
            }).catch(() => { })
        },
        getDictLabel(dictType, value) {
            let type = ""
            this.dict.type.abnormalstatus.forEach(item => {
                if (item.value == value) {
                    type = item.label
                }
            })
            return type
        },
        dictValueToTagType(status) {
            let type = ""
            this.dict.type.abnormalstatus.forEach(item => {
                if (item.value == status) {
                    type = item.raw.listClass
                }
            })
            return type
        },
        /** 导出按钮操作 */
        handleExport() {
            this.download('/business/appraisal/export', {
                ...this.queryParams,
                ids: this.ids
            }, `会员测评列表_${new Date().getTime()}.xlsx`)
        },
        changeDate(e) {
            this.queryParams.params.beginTime = e[0]
            this.queryParams.params.endTime = e[1]
        },
        generateReport() {
            const loading = this.$loading({
                lock: true,
                text: 'Loading',
                spinner: 'el-icon-loading',
                background: 'rgba(0, 0, 0, 0.7)'
            });
            setTimeout(() => {
                this.$refs.html2Pdf.generatePdf()
                loading.close();
            }, 2000);
        },
        handleViews(row) {
            this.appraisalId = row.appraisalId;
            this.detailId = row.id;
            this.openResult = true
        },
        /** 查询配置维护列表 */
        getList() {
            this.loading = true;
            userAppraisalList1(this.queryParams).then(response => {
                this.configurationList = response.rows;
                this.total = response.total;
                this.loading = false;
            });
        },
        // 取消按钮
        cancel() {
            this.open = false;
            this.reset();
        },
        /** 搜索按钮操作 */
        handleQuery() {
            this.queryParams.pageNum = 1;
            this.getList();
        },
        /** 重置按钮操作 */
        resetQuery() {
            this.dates = []
            this.queryParams.params.beginTime = null
            this.queryParams.params.endTime = null
            this.resetForm("queryForm");
            this.handleQuery();
        },
        // 多选框选中数据
        handleSelectionChange(selection) {
            this.ids = selection.map(item => item.id)
            this.single = selection.length !== 1
            this.multiple = !selection.length
        }
    }
};
</script>
